<template>
	<!-- 底部导航 -->
	<view>
		<view class="page-footer" id="target">
			<view :style="[bgColor]" class="flex-around-center bg-box">
				<view class="foot-item foot-item1" v-for="(item,index) in bottomNavigationList" :key="index"
					@click="goRouter(item)">
					<block v-if="item.link.split('?')[0] == activeRouter">
						<image v-if="item.checkedImg" :src="item.checkedImg"></image>
						<u-icon v-else class="checkedicon" :name="item.icon" :color="item.checkcolor?item.checkcolor:'var(--color-primary)'" size="56rpx"></u-icon>
						<view class="txt">{{item.name}}</view>
					</block>
					<block v-else>
						<image v-if="item.uncheckedImg" :src="item.uncheckedImg"></image>
						<u-icon v-else class="uncheckedicon" color="#9e9e9e" :name="item.icon" size="56rpx"></u-icon>
						<view class="unchecked" :style="fontColor">{{item.name}}</view>
					</block>
				</view>
			</view>
		</view>
		<view class="placeholder"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from "vuex"
	let app = getApp();
	export default {
		name: 'pageFooter',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			value: {
				type: Array,
				default: function() {
					return [];
				}
			}
		},
		computed: {
			bgColor() {
				if (this.dataConfig) {
					return {
						background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
					}
				}
			},
			//标签文字颜色
			fontColor() {
				if (this.dataConfig) {
					return {
						color: this.dataConfig.fontColor.color[0].item
					};
				}

			},
		},
		created() {
			let routes = getCurrentPages(); //获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route //获取当前页面路由
			this.activeRouter = '/' + curRoute;
		},
		mounted() {
			this.bottomNavigationList = this.value;
		},
		data() {
			return {
				isCustom: '',
				bottomNavigationList: [],
				activeRouter: '',
				checkiconColor: ''
			}
		},
		methods: {
			goRouter(item) {
				var pages = getCurrentPages();
				var page = (pages[pages.length - 1]).$page.fullPath;
				if (item.link == page) return
				uni.redirectTo({
					url: item.link
				})
			}
		}
	}
</script>

<style lang="less">
	.overlay {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: calc(98rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
	}

	.unchecked {
		color: #666;
		font-size: 24rpx;
	}

	.page-footer {
		position: fixed;
		bottom: 0;
		z-index: 998;
		display: flex;
		align-items: center;
		justify-content: space-around;
		width: 100%;
		height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
		box-sizing: border-box;
		border-top: solid 1rpx #F3F3F3;
		background-color: #fff;
		box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
		padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
		padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/

		.foot-item {
			display: flex;
			width: max-content;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			position: relative;

			.count-num {
				position: absolute;
				display: flex;
				justify-content: center;
				align-items: center;
				min-width: 30rpx;
				height: 30rpx;
				top: 0rpx;
				right: 25rpx;
				color: #fff;
				font-size: 20rpx;
				background-color: #FD502F;
				border-radius: 50%;
				padding: 0 8rpx;
			}
		}

		.foot-item1 {
			width: 20%;
		}

		.bg-box {
			width: 100%;
			height: 100%;
		}

		.foot-item image {
			height: 50rpx;
			width: 50rpx;
			text-align: center;
			margin: 0 auto;
		}

		.txtchecked {
			font-size: 24rpx;
		}

		.foot-item .txt {
			font-size: 24rpx;
			color:var(--color-primary)
		}
	}

	.placeholder {
		height: calc(100rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(100rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
		padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
		padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
	}
</style>